package org.cjlm.impl;

import org.cjlm.itf.ConnectionProvider;
import org.cjlm.ui.db.DataSourceConfig;
import org.cjlm.ui.db.DataSourceManager;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionProviderImpl implements ConnectionProvider {
    @Override
    public Connection getConnection() {
        DataSourceConfig dataSourceConfig = DataSourceManager.getDefaultDataSource();
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(dataSourceConfig.getUrl(),  dataSourceConfig.getUsername(), new String(dataSourceConfig.getPassword()));
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return conn;
    }
}
